//
// Created by martin on 10/4/21.
//
#include <stdio.h>
#include <stdarg.h>

void my_print(const char *fmt, ...)
{
    char *s = fmt;
    va_list ap;

    va_start(ap, fmt);

    while (s != NULL) {
        printf("%s\n", s);
        s = va_arg(ap, char *);
    }

    va_end(ap);
}

int sum(int v, ...)
{
    int i = v;
    int s = 0;

    va_list ap;
    va_start(ap, v);

    while (i > 0) {
        s += va_arg(ap, int);
        i--;
    }

    //  {
    volatile int tmp = va_arg(ap, int); // tmp是未知值
    printf("tmp = %d\n", tmp);
    // } 用于测试

    va_end(ap);

    return s;
}

/**
 * 可变参数的函数例程
 */
int main()
{
    my_print("hello", "yes", "no");

    int s = sum(3,2,3,4);
    printf("sum = %d\n", s);
    return 0;
}
